% PLOT AVERAGE DISPLACEMENTS OVER ALL TRIALS
% for fast speed data (22 deg/s)

fig6xlimit = [0 5500];
fig6ylimit = [-50 50];

% figure(3)
% plot(PlotSmooth.time,PlotSmooth.mean,'-r')       
% hold on
% plot(PlotNoisy.time,PlotNoisy.mean)
% plot(target22.X,'-k','LineWidth',1.5)
% for i = 1:6
%     patch(target22.plotocc.x(i,:),target22.plotocc.y(i,:),[0.9,0.9,0.9]);
%     set(patch,'facealpha',0.5)
% end
% xlabel('Time (ms)');
% ylabel('Displacement (pixels)')
% legend('22\circ/s Smooth','22\circ/s Noisy','Location','SouthEast')
% title('Mean displacement over all trials','FontWeight','bold')
% 
% try
%     suplabel(subject,'t')
% catch
%     
% end


% PLOT AVERAGE DISPLACEMENTS OVER ALL CYCLES

figure(4)
plot(PlotSmooth.mean, '-r')
hold on
plot(PlotNoisy.mean)
plot(target22.one,'-k','LineWidth',1.5)
for i = 1:2
    patch(target22.plotocc.x(i,:),target22.plotocc.y(i,:),[0.9,0.9,0.9]);
    set(patch,'facealpha',0.5)
end
xlabel('Time (ms)');
ylabel('Displacement (pixels)')
legend('22\circ/s Smooth','22\circ/s Noisy','Location','SouthEast')
title('Mean displacement over all cycles','FontWeight','bold')

try
    suplabel(subject,'t')
catch
    
end


% PLOT VELOCITIES INCLUDING SACCADES

% figure(5)
% plot(PlotSmooth.time,PlotSmooth.meanvel,'-r')       
% hold on
% plot(PlotNoisy.time,PlotNoisy.meanvel)
% plot(target22.Xvel,'-k','LineWidth',1.5)
% for i = 1:6
%     patch(target22.plotocc.x(i,:),target22.plotocc.yvel(i,:),[0.9,0.9,0.9]);
%     set(patch,'facealpha',0.5)
% end
% xlabel('Time (ms)');
% ylabel('Velocity (degrees/sec)');
% legend('22\circ/s Smooth','22\circ/s Noisy','Location','SouthEast')
% title('Mean velocities over all trials (incl. saccades: calculated from mean displacement)',...
%     'FontWeight','bold');
% 
% try
%     suplabel(subject,'t')
% catch
%     
% end


figure(6)
plot(PlotSmooth.meanvel, '-r')
hold on
plot(PlotNoisy.meanvel)
plot(target22.onevel,'-k','LineWidth',1.5)
for i = 1:2
    patch(target22.plotocc.x(i,:),target22.plotocc.yvel(i,:),[0.9,0.9,0.9]);
    set(patch,'facealpha',0.5)
end
xlabel('Time (ms)');
ylabel('Velocity (degrees/sec)');
% xlim(fig6xlimit);
% ylim(fig6ylimit);
legend('22\circ/s Smooth','22\circ/s Noisy','Location','SouthEast')
title('Mean velocities over all cycles (incl. saccades: calculated from mean displacement)',...
    'FontWeight','bold')

try
    suplabel(subject,'t')
catch
    
end


% PLOT VELOCITIES EXCLUDING SACCADES

% figure(7)
% plot(PlotSmooth.time,PlotSmooth.meanvelnosac,'-r')       
% hold on
% plot(PlotNoisy.time,PlotNoisy.meanvelnosac)
% plot(target22.Xvel,'-k','LineWidth',1.5)
% for i = 1:6
%     patch(target22.plotocc.x(i,:),target22.plotocc.yvel(i,:),[0.9,0.9,0.9]);
%     set(patch,'facealpha',0.5)
% end
% xlabel('Time (ms)');
% ylabel('Velocity (degrees/sec)')
% legend('22\circ/s Smooth','22\circ/s Noisy','Location','SouthEast')
% title('Mean velocities over all trials (excluding saccades)','FontWeight','bold')
% 
% try
%     suplabel(subject,'t')
% catch
%     
% end


figure(8)
plot(PlotSmooth.meanvelnosac, '-r')
hold on
plot(PlotNoisy.meanvelnosac)
plot(target22.onevel,'-k','LineWidth',1.5)
for i = 1:2
    patch(target22.plotocc.x(i,:),target22.plotocc.yvel(i,:),[0.9,0.9,0.9]);
    set(patch,'facealpha',0.5)
end
xlabel('Time (ms)');
ylabel('Velocity (degrees/sec)')
legend('22\circ/s Smooth','22\circ/s Noisy','Location','SouthEast')
title('Mean velocities over all cycles (excluding saccades)','FontWeight','bold')

try
    suplabel(subject,'t')
catch
    
end


% PLOT RMSE'S OVERALL AND FOR IN/OUT OF OCCLUDER

Label = {'22 deg/s Noisy';'22 deg/s Smooth'};

figure(9)
bar(Stats.RMSE)
set(gca,'XTickLabel',Label)
xlabel('Trial types')
ylabel('RMS error')
title('RMS errors for whole trials and occluded/visible periods','FontWeight','bold')
legend('RMSE for whole trial','RMSE for occluder',...
    'RMSE for visible target')
try
    suplabel(subject,'t')
catch
    
end


% PLOT GAINS

figure(10)
bar(Stats.gain)
set(gca,'XTickLabel',Label)
xlabel('Trial types')
ylabel('Gain (average eye/target velocity)')
title('Gain: closed-loop (visible, accel) vs residual predictive (occluded) in accel/deceleration',...
    'FontWeight','bold')
legend('Closed-loop gain','Resid pred gain (accel)',...
    'Resid pred gain (decel)')
try
    suplabel(subject,'t')
catch
    
end


% PLOT MEAN VELOCITY ERRORS

figure(11)
bar(Stats.velerr)
set(gca,'XTickLabel',Label)
xlabel('Trial types')
ylabel('Mean velocity error (target - eye velocity)')
title('Mean velocity error: closed-loop (visible, accel) vs residual predictive (occluded) in accel/deceleration',...
    'FontWeight','bold')
legend('Closed-loop v error','Res pred v error (accel)',...
    'Res pred v error (decel)')
try
    suplabel(subject,'t')
catch
    
end


% PLOT LAGS

figure(12)
Nbar = bar(PlotNoisy.time, PlotNoisy.lag, 'FaceColor', 'b','EdgeColor', 'b');
Nbar = findobj(gca,'Type','patch');
set(Nbar,'facealpha', 0.1, 'edgealpha', 0.1);
hold on
Sbar = bar(PlotSmooth.time, PlotSmooth.lag, 'FaceColor', 'r','EdgeColor', 'r');
Sbar = findobj(gca,'Type','patch');
set(Sbar,'facealpha', 0.1, 'edgealpha', 0.1);
xlabel('Time (ms)')
ylabel('Eye position relative to target (pixels)')
plot(target22.one,'-k','LineWidth',0.5)
for i = 1:2
    patch(target22.plotocc.x(i,:),target22.plotocc.y(i,:),[0.9,0.9,0.9]);
    set(patch,'facealpha',0.5)
end
title('Lag of eye behind target','FontWeight','bold')
legend('22\circ/s Noisy','22\circ/s Smooth','Location','SouthEast')

try
    suplabel(subject,'t')
catch
    
end
